package com.aplink.generic.widgets;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;

import com.aplink.generic.GenericFragment;
import com.aplink.generic.dictionary.GenericDictionary;
import com.aplink.generic.interfaces.OnGetObjProInfo;
import com.aplink.generic.pojo.GenericAttribute;
import com.aplink.generic.pojo.ObjPropInfo;
import com.aplink.generic.pojo.controlspec.ControlSpec;
import com.aplink.generic.pojo.controlspec.RadioButtonSpec;
import com.aplink.generic.util.Language;

public class ApLinkRadioButton extends ApLinkBaseView {
	private final RadioButton mRadioButton;
	private final RadioButtonSpec mRadioButtonSpec;

	public ApLinkRadioButton(final GenericFragment genericFragment,
	        final ControlSpec controlSpec, final View view, Bundle bundle) {
		super(genericFragment, controlSpec, view, bundle);
		this.mRadioButton = (RadioButton) view;
		this.mRadioButtonSpec = (RadioButtonSpec) controlSpec;
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub

	}

	@Override
	public GenericAttribute getAttribute() {
		final String name = this.mRadioButtonSpec.getFullColumnName();
		final String value = this.mRadioButtonSpec.getValue();
		final ObjPropInfo objPropInfo = getGenericFragment().getContentData()
		        .get(name);
		return GenericAttribute.obtain(value, objPropInfo);
	}

	@Override
	public GenericDictionary<String, GenericAttribute> getListAttributes() {
		return null;
	}

	@Override
	public RadioButton getView() {
		return this.mRadioButton;
	}

	@Override
	protected void initViewProperties() {
		this.mRadioButton.setChecked(this.mRadioButtonSpec.isChecked());
		this.mRadioButton.setTag(this.mRadioButtonSpec);
	}

	@Override
	public void languageChanged() {
		mRadioButton.setText(Language.getInstance().get(
		        mRadioButton.getText().toString()));
	}

	@Override
	protected void loadBindingObject() {

	}

	@Override
	protected void loadDefaultObject() {

	}

	@Override
	protected void setEventListener() {
		this.mRadioButton.setOnClickListener(getGenericFragment());
	}

	@Override
	public void setObjPropInfoTemp(final OnGetObjProInfo getObjProInfo) {
		throw new UnsupportedOperationException(this.getClass().getSimpleName()
		        + " is not support this method");
	}

	@Override
	public void setOnClickListener(final OnClickListener onClickListener) {
		throw new UnsupportedOperationException(this.getClass().getSimpleName()
		        + " is not support this method");
	}
}
